<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户所属组管理</title>
    <?php include(APPLICATION_BASE_TPL_PATH . "/inc/include.phtml"); ?>

    <link href="<?=APP_STATIC_PATH?>/admin/ext/chosen/chosen.min.css" rel="stylesheet">
	<script src="<?= APP_STATIC_PATH ?>/admin/ext/chosen/chosen.jquery.min.js"></script>
</head>
<body>
<div id="wrapper">
    <?php echo $menuview; ?>

	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">用户所属组管理</h1>
			</div>
			<!-- /.col-lg-12 -->
		</div>

		<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title" id="uname">用户：<?=$user['uname']?></h4>
						<input type="hidden" id="uid" value="<?=$user['uid']?>">
					</div>
					<div class="modal-body">
						<div class="form-group">
							<select  class="form-control chosen-select" id="group" name="group[]" data-placeholder="点击选择用户所属组" multiple>
								<?php if (is_array($groups)) foreach ($groups as $k=>$v) {
									$select = is_array($group) && in_array($v['gid'], $group) ? 'selected="selected"' : '';
									echo "<option value=\"{$v['gid']}\" {$select}>{$v['gname']}</option>";
								}
								?>
							</select>
						</div>
					</div>
					<div class="modal-footer">
						<span class="tips" id="atip"></span>
						<button type="button" id="cancel" class="btn btn-default" data-dismiss="modal">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
						<button type="button" id="add" class="btn btn-primary">&nbsp;&nbsp;确认&nbsp;&nbsp;</button>
					</div>
				</div>
			</div>
		</div>

		<!-- /#page-wrapper -->

	</div>
	<!-- /#wrapper -->

<script type="text/javascript">
$(document).ready(function () {
	var config = {
		'.chosen-select'           : {},
		'.chosen-select-deselect'  : {allow_single_deselect:true},
		'.chosen-select-no-single' : {disable_search_threshold:10},
		'.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
		'.chosen-select-width'     : {width:"95%"}
	};
	for (var selector in config) {
		$(selector).chosen(config[selector]);
	}

	$('#add').click(function(){
		var uid     = $('#uid').val();
		var gids    = $('#group').val();

        <?php if(!$group) { ?>
		if (!gids) {
			alert('请选择用户组');
			$('#group').focus();
			return false;
		}
        <?php } ?>

		$.post(url('/group/saveusergroup'), {uid:uid, gids:gids}, function(ret){
			if (ret.retcode == 2000000) {
				alert('操作成功');
			} else {
				alert(ret.msg);
			}
		}, 'json');

	});

	$('#cancel').click(function(){
        refresh();
	});
});
</script>
</body>

</html>







